package com.simple.datax.intra.service.impl;

import java.util.UUID;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.rpc.RpcException;
import com.simple.datax.SimpleMessage;
import com.simple.datax.api.MessageProcessor;
import com.simple.datax.api.MessageService;
import com.simple.datax.utils.SimpleConstants;

/**
 * @Title: IntraReceiverImpl.java
 * @Package com.simple.datax.intra.service.impl
 * @Description: 内部服务接收器
 * @author Paladin Chen
 * @date 2013-1-4 下午3:41:44
 * @version V1.0
 */
public class IntraReceiverImpl implements MessageService {
	private static final Logger logger = LoggerFactory.getLogger(IntraReceiverImpl.class);

	private MessageProcessor nextProc;

	@Override
	public void service(String ecxml) {
		logger.debug("Begin To IntraReceiver service ......");

		SimpleMessage sm = new SimpleMessage();

		sm.setRecvRawMsgid(UUID.randomUUID().toString());
		sm.setContent(ecxml);
		sm.setCommunType("RPC."+SimpleConstants.FLOW_COMMTYPE_POSTFIX);
		sm.setCommunParam("Intra Service");
		sm.setIntraMsg(true);

		try {
			nextProc.process(sm);
		} catch (RpcException e) {
            logger.error(sm.toLog() + "Intra Receiver Call Next Processor Rpc Error:", e);
		} catch (Exception e) {
			logger.error(sm.toLog() + "Intra Receiver Call Next Processor Error:", e);
		}

		logger.debug("Finish IntraReceiver service ......" + sm.toLog());
	}

	public MessageProcessor getNextProc() {
		return nextProc;
	}

	public void setNextProc(MessageProcessor nextProc) {
		this.nextProc = nextProc;
	}

}
